package com.example.lib_base.loadutil

import kotlinx.coroutines.Dispatchers.Main
import kotlinx.coroutines.MainScope
import kotlinx.coroutines.launch
/**子线程切换到主线成的监听接口*/
class ChildToMainUtil {
    interface MainCallBack{
        fun mainCallback(string:String?)
    }
    /**子线程切换到主线成的监听接口*/
    interface NetTOMainCallBack{
        fun callback(string:String?)
    }

    lateinit var mainCallBack:MainCallBack
    /**子线程切换到主线成的监听接口*/
    val childCallBack = object : NetTOMainCallBack {
        override fun callback(string: String?) {
            MainScope().launch(Main){
                if(::mainCallBack.isInitialized) {
                    mainCallBack.mainCallback(string)
                }
            }
        }

    }
}